package com.syedu.day13.homework1;

import org.apache.commons.lang3.ArrayUtils;

import java.util.Arrays;

/**
 * description：
 * 写一个程序,使用数组存放99个随机数(不重复,数字为1-100之间),
 * 判断哪个数字没有被随机到?
 *
 * @author Administrator
 * @date 2022/3/28 11:17
 */
public class ArrayExercise {
    public static void main(String[] args) {
        int[] arr = {};
        for (int i = 1; i <= 99; ) {
            int randomNumber = (int) (Math.random() * 100 + 1);
            if (!isExists(randomNumber, arr)) {
                arr = ArrayUtils.add(arr, randomNumber);
                i++;
            }
        }
        System.out.println(Arrays.toString(arr));
        //1-100的总和-当前数组元素总和即结果
    }

    public static boolean isExists(int number, int[] arr) {
        boolean isExits = false;
        for (int i = 0; i < arr.length; i++) {
            if (number == arr[i]) {
                isExits = true;
                break;
            }
        }
        return isExits;
    }
}